Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore frames from frame collection logic #167

Closed

Conversation

beniwohli
Copy link
Contributor

this should clean up the collected stack traces quite a bit

Note, for Django this has been done a bit differently, this
specialization has been removed.

Before:

After:

@beniwohli beniwohli force-pushed the ignore-frame-collection-frames branch 2 times, most recently from 3345df1 to c0d7c11 Compare February 21, 2018 09:23
if not _getitem_from_frame(f_locals, '__traceback_hide__'):
f_globals = getattr(frame, 'f_globals', {})
if not (f_globals.get('__name__', '').startswith(ignore_modules)
or _getitem_from_frame(f_locals, '__traceback_hide__')):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line break before binary operator

f_locals = getattr(frame, 'f_locals', {})
f_globals = getattr(frame, 'f_globals', {})
if not (f_globals.get('__name__', '').startswith(ignore_modules)
or _getitem_from_frame(f_locals, '__traceback_hide__')):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line break before binary operator

if not _getitem_from_frame(f_locals, '__traceback_hide__'):
f_globals = getattr(frame, 'f_globals', {})
if not (f_globals.get('__name__', '').startswith(ignore_modules)
or _getitem_from_frame(f_locals, '__traceback_hide__')):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line break before binary operator

f_locals = getattr(frame, 'f_locals', {})
f_globals = getattr(frame, 'f_globals', {})
if not (f_globals.get('__name__', '').startswith(ignore_modules)
or _getitem_from_frame(f_locals, '__traceback_hide__')):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line break before binary operator

@beniwohli beniwohli force-pushed the ignore-frame-collection-frames branch 2 times, most recently from 98b7fdb to 737c0c5 Compare February 21, 2018 11:50
beniwohli added a commit to beniwohli/apm-agent-python that referenced this pull request Feb 21, 2018
…ic#167)

this should clean up the collected stack traces quite a bit

Note, for Django this has been done a bit differently, this
specialization has been removed.

closes elastic#167
@beniwohli beniwohli force-pushed the ignore-frame-collection-frames branch from 737c0c5 to c353f9c Compare February 21, 2018 11:52
beniwohli added a commit to beniwohli/apm-agent-python that referenced this pull request Feb 21, 2018
…ic#167)

this should clean up the collected stack traces quite a bit

Note, for Django this has been done a bit differently, this
specialization has been removed.

closes elastic#167
…ic#167)

this should clean up the collected stack traces quite a bit

Note, for Django this has been done a bit differently, this
specialization has been removed.

closes elastic#167
@beniwohli beniwohli force-pushed the ignore-frame-collection-frames branch from c353f9c to f857a0a Compare February 21, 2018 13:34
while len(frames) > i:
if 'module' in frames[i] and not (
frames[i]['module'].startswith('elasticapm.') or
frames[i]['module'] == 'contextlib'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens with contextlib, don't we want to filter it out anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a relic from the olden days. We don't use contextlib anywhere in the code base

Frames can be skipped by either providing a number, or a tuple
of module names. If the module of a frame matches one of the names
(using `.startswith`, that frame will be skipped. This matching will only
be done until the first frame doesn't match.
Copy link
Contributor

@jalvz jalvz Feb 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know you are doing this in a generic way, but for now you are only using it for the elasticapm.
in that case, don't you want to filter them out if even they are interleaved (like elasticapm.something -> database.something -> elasticapm.something_else)?
if that can not happen, why go through the troubles of implementing some logic you dont need?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad you asked :D I actually intend to filter more than just elasticapm.. In #164, I introduce a functools.partial call. In CPython, this doesn't create a frame (I suppose because it's implemented in C? Not sure). But in PyPy, this creates a frame, with the module _functools. So my intention is to rebase that PR after merging this one, and then adding _functools to that list. But we only want to kill that one frame at the top, and not any functool.partial calls that come later on.

Another argument for not filtering out all frames that match is that this should only be used to cut away the top frames of the stack trace that are introduced by stack collection itself. If you call into any elasticapm code in other parts of the stack, that should IMO not be suppressed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes perfect sense. i am wiser now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there it is:

if platform.python_implementation() == 'PyPy':
# PyPy introduces a `_functools.partial.__call__` frame due to our use
# of `partial` in AbstractInstrumentedModule
skip_modules = ('elasticapm.', '_functools')
else:
skip_modules = ('elasticapm.',)

@beniwohli beniwohli closed this in 3d68d1a Feb 21, 2018
beniwohli added a commit that referenced this pull request Feb 21, 2018
this should clean up the collected stack traces quite a bit

Note, for Django this has been done a bit differently, this
specialization has been removed.

closes #167
@beniwohli beniwohli deleted the ignore-frame-collection-frames branch February 21, 2018 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants